//package com.aiyige.page.my.order.myOrder;
//
//import android.content.Intent;
//import android.net.Uri;
//import android.os.Bundle;
//import android.support.annotation.Nullable;
//import android.text.TextUtils;
//import android.util.Log;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.widget.ImageView;
//import android.widget.LinearLayout;
//import android.widget.RelativeLayout;
//import android.widget.TextView;
//
//import com.aiyige.R;
//import com.aiyige.arouter.Router;
//import com.aiyige.arouter.config.ARouterConfig;
//import com.aiyige.base.BaseActivity;
//import com.aiyige.base.api.JsonUtil;
//import com.aiyige.city.model.City;
//import com.aiyige.model.AgreementBackup;
//import com.aiyige.model.Subject;
//import com.aiyige.model.enums.GoodsType;
//import com.aiyige.model.moment.entity.Guarantee;
//import com.aiyige.model.moment.entity.MajorCourse;
//import com.aiyige.model.moment.entity.TrainingCourse;
//import com.aiyige.model.request.OrderDetailRequest;
//import com.aiyige.model.request.OrderStatusEnum;
//import com.aiyige.page.detail.dialog.DialogSafeguard;
//import com.aiyige.page.my.order.orderDetail.OrderDetailManager;
//import com.aiyige.page.my.order.orderDetail.OrderDetailModelData;
//import com.aiyige.utils.DummyDataUtil;
//import com.aiyige.utils.GlideUtil;
//import com.aiyige.utils.ListUtil;
//import com.aiyige.utils.StringUtils;
//import com.aiyige.utils.TimeUtils;
//import com.aiyige.utils.UIHelper;
//import com.alibaba.android.arouter.facade.annotation.Autowired;
//import com.alibaba.android.arouter.facade.annotation.Route;
//import com.alibaba.android.arouter.launcher.ARouter;
//
//import butterknife.BindView;
//import butterknife.ButterKnife;
//import butterknife.OnClick;
//
///**
// * Created by xiachao on 2017/11/23.
// */
//
//@Route(path = ARouterConfig.MyOrderDetailFinishPage)
//public class MyOrderDetailFinishPage extends BaseActivity {
//
//    @BindView(R.id.iv_cover)
//    ImageView ivCover;
//    @BindView(R.id.iv_head)
//    ImageView ivHead;
//
//    @BindView(R.id.tv_title)
//    TextView tvTitle;
//    @BindView(R.id.tv_tag)
//    TextView tvTag;
//    @BindView(R.id.tv_count)
//    TextView tvCount;
//    @BindView(R.id.tv_pay_amount_value)
//    TextView tvPayAmountValue;
//    @BindView(R.id.tv_pay_amount)
//    TextView tvPayAmount;
//    @BindView(R.id.tv_order_status)
//    TextView tvOrderStatus;
//    @BindView(R.id.tv_order_status_value)
//    TextView tvOrderStatusValue;
//
//    @BindView(R.id.tv_order_id)
//    TextView tvOrderId;
//    @BindView(R.id.tv_order_time)
//    TextView tvOrderTime;
////    @BindView(R.id.ll_order_detail)
////    LinearLayout llOrderDetail;
//    @BindView(R.id.tv_seller)
//    TextView tvSeller;
//    //    @BindView(R.id.tv_service_phone)
////    TextView tvServicePhone;
//    @BindView(R.id.rl_order_content)
//    RelativeLayout rlOrderContent;
//
//    @BindView(R.id.ll_price)
//    RelativeLayout llPrice;
//    @BindView(R.id.tv_order_mode_of_payment)
//    TextView tvOrderModeOfPayment;
//    @BindView(R.id.tv_service_number)
//    TextView tvServiceNumber;
//    @BindView(R.id.tv_pay_time)
//    TextView tvPayTime;
//    @Autowired
//    public String orderId;
//    @BindView(R.id.tv_content_count)
//    TextView tvContentCount;
//    @BindView(R.id.tv_price)
//    TextView tvPrice;
//
//
//    @BindView(R.id.rl_title_layout)
//    RelativeLayout rlTitleLayout;
//    @BindView(R.id.ll_safeguard)
//    LinearLayout safeguardContentLayout;
//
//    @BindView(R.id.tv_city_and_start_date)
//    TextView tvCityAndStartDate;
//
//    @BindView(R.id.ll_city)
//    RelativeLayout rlCityAndStartDate;
//
//    private OrderDetailModelData detailEntity;
//
//    @Override
//    public void onCreate(@Nullable Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.page_my_order_detail_finish);
//        ButterKnife.bind(this);
//        ARouter.getInstance().inject(this);
//        requestData();
//    }
//
//    private void requestData() {
//        OrderDetailManager.getInstance().requestOrderDetail(OrderDetailRequest.type_buyer, orderId, new OrderDetailManager.OrderDetailCallback() {
//            @Override
//            public void success(OrderDetailModelData orderDetailModelData) {
//                detailEntity = orderDetailModelData;
//                fillViews();
//            }
//        });
//    }
//
//    private void fillViews() {
//        if (detailEntity == null) {
//            return;
//        }
//        GlideUtil.with(this).big().loadCover(detailEntity.getCover())
//                .into(ivCover);
//        GlideUtil.with(this).small().loadAvatar(detailEntity.getSellerAvatar())
//                .into(ivHead);
//        tvTitle.setText(detailEntity.getTitle());
//        tvTag.setText(GoodsType.getValueByKey(detailEntity.getGoodsType() + ""));
//        tvPayAmountValue.setText(StringUtils.priceFormat(detailEntity.getPayAmount()));
//
//        tvCount.setText("x" + detailEntity.getNum());
//        tvOrderTime.setText(getResources().getString(R.string.order_time_value, TimeUtils.dateToYYYYMMDDHHSS(detailEntity.getCreateTime())));
//        tvOrderStatus.setText(getResources().getString(R.string.order_status_tag));
//        tvOrderStatusValue.setText(OrderStatusEnum.getValueByKey(detailEntity.getStatus()));
//        tvOrderId.setText(getResources().getString(R.string.order_id_value, detailEntity.getCode() + ""));
//        tvSeller.setText(detailEntity.getSellerName());
////        tvServicePhone.setText(getResources().getString(R.string.service_phone_value, detailEntity.getSellerMobile()));
////        tvContentCount.setVisibility(detailEntity.getVideoStages() > 0 ? View.VISIBLE : View.INVISIBLE);
////        tvContentCount.setText(getString(R.string.content_count_value, detailEntity.getVideoStages() + ""));
//
//        tvOrderModeOfPayment.setText(getResources().getString(R.string.order_mode_of_payment_value, detailEntity.getPayMethodString()));
//        tvServiceNumber.setText(getResources().getString(R.string.service_number_value, detailEntity.getPayCode()));
//        tvPayTime.setText(getResources().getString(R.string.pay_time_value, TimeUtils.dateToYYYYMMDDHHSS(detailEntity.getPayTime())));
//        tvPrice.setText("￥"+StringUtils.priceFormat(detailEntity.getAmount()));
//
//
//        AgreementBackup agreementBackup = ListUtil.isEmpty(detailEntity.getAgreementBackup()) ? null : detailEntity.getAgreementBackup().get(0);
//        if (agreementBackup != null && agreementBackup.getDetailBackup() != null && !ListUtil.isEmpty(agreementBackup.getDetailBackup().getGuarantee())) {
//            findViewById(R.id.rl_safeguard_info).setVisibility(View.VISIBLE);
//            if (safeguardContentLayout.getChildCount() == 0) {
//                int max = 0;
//                for (Guarantee entity : agreementBackup.getDetailBackup().getGuarantee()) {
//                    if (entity == null) continue;
//                    max++;
//                    if (max > 4) {// 详情页外面，最多展示4个
//                        break;
//                    }
//                    LinearLayout view = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.item_safeguard_tag, null);
//                    TextView title = (TextView) view.findViewById(R.id.tv_tag1);
//                    title.setText(entity.getName());
//                    view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT));
//                    safeguardContentLayout.addView(view);
//                }
//            }
//        }
////        // 培训班
////        if (detailEntity.getGoodsType() != null && detailEntity.getGoodsType().equals(Subject.training_course)) {
////            if (agreementBackup != null && !TextUtils.isEmpty(agreementBackup.getMoreBackup())) {
////                TrainingCourse trainingCourse = JsonUtil.toObject(agreementBackup.getMoreBackup(), TrainingCourse.class);
////                City city = DummyDataUtil.getCityById((agreementBackup.getCityId()));
////                if (trainingCourse != null) {
////                    tvCityAndStartDate.setText(city.getCity() + "/" + getString(R.string.open_class_date_value,trainingCourse.getStartClassTime()));
////                }
////                tvContentCount.setVisibility(detailEntity.getClassCount() > 0 ? View.VISIBLE : View.INVISIBLE);
////                tvContentCount.setText(detailEntity.getClassCount() + getString(R.string.class_count));
////            }
////        }
//        // 专业课程
//        if (detailEntity.getGoodsType() != null && detailEntity.getGoodsType().equals(Subject.major_course)) {
//            if (agreementBackup != null && !TextUtils.isEmpty(agreementBackup.getMoreBackup())) {
//                MajorCourse majorCourse = JsonUtil.toObject(agreementBackup.getMoreBackup(), MajorCourse.class);
//                City city = DummyDataUtil.getCityById((agreementBackup.getCityId()));
//                if (majorCourse != null) {
//                    tvContentCount.setVisibility(majorCourse.getClassCount() > 0 ? View.VISIBLE : View.INVISIBLE);
//                    tvContentCount.setText(majorCourse.getClassCount() + getString(R.string.class_count));
//                    tvCityAndStartDate.setText(city.getCity() + "/" + getString(R.string.start_class_info_value, majorCourse.getStartClassTime()));
//                }
//            }
//        } else if (detailEntity.getGoodsType() != null && detailEntity.getGoodsType().equals(Subject.video_course)) {
//            try {
//                LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tvPrice.getLayoutParams();
//                lp.topMargin = UIHelper.dip2px(this,-63);
//                tvPrice.setLayoutParams(lp);
//                RelativeLayout.LayoutParams lpCount = (RelativeLayout.LayoutParams) tvCount.getLayoutParams();
//                lpCount.bottomMargin = UIHelper.dip2px(this,15);
//                tvCount.setLayoutParams(lpCount);
//            } catch (Exception e) {
//                Log.i("",""+e.toString());
//            }
//            rlCityAndStartDate.setVisibility(View.INVISIBLE);
//            tvContentCount.setVisibility(detailEntity.getVideoStages() > 0 ? View.VISIBLE : View.INVISIBLE);
//            tvContentCount.setText(getString(R.string.content_count_value, detailEntity.getVideoStages() + ""));
//        }
//
//
//    }
//
//    private void orderCancel() {
//
//    }
//
//    private void orderPay() {
//
//    }
//
//    @OnClick({R.id.titleBackBtn, R.id.ll_service_phone, R.id.rl_order_content, R.id.rl_safeguard_info,R.id.ll_head})
//    public void onViewClicked(View view) {
//        switch (view.getId()) {
//            case R.id.titleBackBtn:
//                finish();
//                break;
//            case R.id.ll_service_phone:
//                if (detailEntity == null || TextUtils.isEmpty(detailEntity.getMobile())) {
//                    return;
//                }
//                Intent intent1 = new Intent(Intent.ACTION_DIAL);
//                intent1.setData(Uri.parse("tel:" + detailEntity.getMobile()));
//                startActivity(intent1);
//                break;
//            case R.id.rl_order_content:
//                if (detailEntity == null) {
//                    return;
//                }
//                if (detailEntity.getGoodsType().endsWith(Subject.major_course)) {
//                    Router.startAiyigeH5(detailEntity.getRouter());
//                } else {
//                    Router.start(detailEntity.getRouter());
//                }
//                break;
//            case R.id.rl_safeguard_info:
//                if (detailEntity == null) {
//                    return;
//                }
//                AgreementBackup agreementBackup = ListUtil.isEmpty(detailEntity.getAgreementBackup()) ? null : detailEntity.getAgreementBackup().get(0);
//                if (agreementBackup != null && agreementBackup.getDetailBackup() != null && !ListUtil.isEmpty(agreementBackup.getDetailBackup().getGuarantee())) {
//                    DialogSafeguard.showAsDropDown(MyOrderDetailFinishPage.this, agreementBackup.getDetailBackup().getGuarantee(), rlTitleLayout);
//                }
//                break;
//            case R.id.ll_head:
//                if (detailEntity != null && !TextUtils.isEmpty(detailEntity.getSellerId())) {
//                    ARouter.getInstance().build(ARouterConfig.UserPage)
//                            .withString("userId",detailEntity.getSellerId())
//                            .navigation();
//                }
//                break;
//        }
//    }
//}
